package controllers;

import java.util.Arrays;
import java.util.List;

import models.About;
import models.Article;
import models.Category;
import play.db.Model;
import play.mvc.Before;
import play.mvc.Controller;

import com.google.gson.Gson;

public class Application extends Controller {
	
	
	@Before
	public static void recentAritlce(){
		
		//TODO 加入缓存
		List<Model> recentArticles = Article.recentArticle(5);
		renderArgs.put("recentArticles", recentArticles);
		
		List<Model> hotArticles = Article.hotArticle(5);
		renderArgs.put("hotArticles", hotArticles);
		
	}

	public static void index() {
		List<Category> channels = Category.getChannelList();
		render(channels);

	}
	
	public static void article(Long id){
		Article article = Article.findById(id);
		if(article == null) article = new Article();
		render(article);
	}
	
	public static void about(){
		About about = About.findById(1L);
		if(about == null) about = new About();
		render(about);
	}
}